package ua.pp.bizon.yandex.api;

import ua.pp.bizon.yandex.api.impl.Element;

import java.util.Collections;
import java.util.List;

import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Query extends NotificationBroadcasterSupport implements QueryMBean {

	private static final Log log = LogFactory.getLog(Query.class);
	private int sequenceNumber = 0;

	public Element getLastActivity() {
		List<Element> activities = getActivities();
		return activities.get(activities.size());
	}

	public void addActivity(Element element) {
		sendNotification(new Notification(Element.class.getName(), element, sequenceNumber++));
		log.debug("activity " + element + " added");
	}

	public List<Element> getActivities() {
		return Collections.unmodifiableList(ObjectLookup.lookup(IJobExecutor.class).getStateInfo());
	}

}
